package com.josephxu.tank.singleton;

/**
 * @Author: Joseph Xu
 * @Date: 2022/1/24 21:38
 * 静态内部类方法方式
 * JVM保证单例
 * 加载外部类时不会加载内部类，这样可以实现懒加载
 *
 *
 */
public class Mgr07 {
    private Mgr07(){

    }
    private static class Mgr07Holder {
        private final static Mgr07 INSTANCE = new Mgr07();
    }

    public static Mgr07 getInstance(){
        return Mgr07Holder.INSTANCE;
    }

    public static void main(String[] args) {

        for (int i = 0; i < 100; i++) {
            new Thread(()->{
                System.out.println(Mgr07Holder.INSTANCE.hashCode());
            }).start();
        }
    }


}
